//	TeleoperationGUI.java --- 

package fr.upmc.dtgui.example.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import java.util.ArrayList;

import javax.swing.JFrame;

import fr.upmc.dtgui.example.robot.LittleRobot;

/**
 * The class <code>TeleoperationGUI</code> is a JFrame representing the
 * overall graphical user interface of a control station for robots.  It
 * has a radar-like display to show the current position of the robot as
 * well as its current direction.  It also has a teleoperation panel,
 * including a panel for the current energy level of the robot, and
 * two panels for control: speed and steering angle.  The two control
 * panel are themselves composed of two subpanels, one for displaying the
 * current value and the other to allow for changing this value.  For
 * readability reasons (Swing does not provide good widgets to show a value
 * with a clear scale besides a slider bar), both of these panels use slider
 * bars.  In the subpanel displaying the current value, actions on the slider
 * bar are not activated.
 * 
 * The control station represented by this Teleoperation GUI is connected
 * to the robot through the reception of sensory data and the sending of
 * actuator commands.  Both of these are implemented as threads, one for
 * sensor data reception and the other for actuator command sending.  The
 * sensor reception thread is created once and for all and it interacts
 * with the Swing GUI by inserting tasks to be scheduled within the main
 * event processing thread.  Threads to send actuator commands are created
 * each time a new data must be sent; they schedule the sending also as a
 * task in the main event proecssing thread, wait for the execution of this
 * task and then simply die. 
 *
 * <p><strong>Invariant</strong></p>
 * 
 * <pre>
 * invariant	true
 * </pre>
 * 
 * <p>Created on : 2011-09-19</p>
 * 
 * @author	<a href="mailto:Jacques.Malenfant@lip6.fr">Jacques Malenfant</a>
 * @version	$Name$ -- $Revision$ -- $Date$
 */
public class			TeleoperationGUI extends JFrame {

	private static final long		serialVersionUID = 1L;
	//protected LittleRobot			lr ;
	protected ArrayList<LittleRobot> robots;
	
	protected PositionDisplay		positionDisplay ;
	protected TeleoperationBoard	board ;
	protected ArrayList<SensorDataReceptor>	sdr ;

	public				TeleoperationGUI(
		/*LittleRobot lr*/ ArrayList<LittleRobot> robots
		) throws HeadlessException
	{
		super("Teleoperation Panel");
		//this.lr = lr;
		this.robots = robots;
		
		this.setSize(1000, 1250) ;
		this.setLayout(new FlowLayout()) ;
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
		this.setLocationRelativeTo(null) ;
		this.positionDisplay =
			new PositionDisplay(Color.green, Color.BLACK, Color.LIGHT_GRAY,
																500, 500, robots.size()) ;
		this.getContentPane().setLayout(new BorderLayout()) ;
		this.add(positionDisplay, BorderLayout.NORTH) ;
		this.board = new TeleoperationBoard(this.robots) ;
		this.add(board, BorderLayout.SOUTH) ;
		
		this.sdr = new ArrayList<SensorDataReceptor>();
		int noRobot = 0;
		for(LittleRobot lr : robots) {
		this.sdr.add(
			new SensorDataReceptor(this.positionDisplay, this.board,
											lr.getSensorDataQueue())) ;
			this.sdr.get(noRobot++).start();
		}
	}

	public void			start() {
		for(LittleRobot lr : robots)
			lr.start() ;
	}
}

// $Id$